﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sobiens.Connectors.Services.SharePoint;
using Sobiens.Connectors.Entities.Settings;
using Sobiens.Connectors.Entities.Interfaces;
using Sobiens.Connectors.Common.SharePoint;
using Sobiens.Connectors.Entities.SharePoint;
using Sobiens.Connectors.Common;
using Sobiens.Connectors.Common.Threading;
using System.Windows.Threading;
using System.Threading;
using Sobiens.Connectors.Entities;
using Sobiens.WPF.Controls.Classes;
using Sobiens.Connectors.WPF.Controls.Outlook;
using Sobiens.WPF.Controls.ExtendedGridControl;
using Microsoft.Windows.Controls;
using Sobiens.Connectors.Entities.Data;
using System.Data;
using System.Collections.Specialized;
using WPF.JoshSmith.ServiceProviders.UI;
using Sobiens.WPF.Controls.UserControls;

namespace Sobiens.Connectors.WPF.Controls
{
    public delegate void SimpleSearchFiltersPanelAfter_ViewChange(IView view);
    public delegate void SimpleSearchFiltersPanelAfter_SearchExecuted(string keyword);


    /// <summary>
    /// Interaction logic for HierarchyNavigator.xaml
    /// </summary>
    public partial class SimpleSearchFiltersPanel : HostControl
    {
        public SimpleSearchFiltersPanel()
        {
            InitializeComponent();
        }

        public event SimpleSearchFiltersPanelAfter_ViewChange After_ViewChange;
        public event PagingControlAfter_PageChange After_PageChange;
        public event SimpleSearchFiltersPanelAfter_SearchExecuted After_SearchExecuted;

        public CamlFilters CustomFilters = new CamlFilters();

        public string Keyword
        {
            get
            {
                return searchTextBox1.Text;
            }
        }

        public void ChangePage(int currentPageIndex, string listItemCollectionPositionNext, int itemCount)
        {
            pagingControl1.ChangePage(currentPageIndex, listItemCollectionPositionNext, itemCount);
        }

        private void ViewsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            IView view = ViewsComboBox.SelectedItem as IView;
            if (view != null)
            {
                if (After_ViewChange != null)
                    After_ViewChange(view);
            }
        }

        private void searchTextBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (After_SearchExecuted != null)
                After_SearchExecuted(searchTextBox1.Text);
        }

        public void LoadViews(List<IView> views)
        {
            ViewsComboBox.Dispatcher.Invoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                ViewsComboBox.Items.Clear();
                ViewsComboBox.Items.Add("Select a view");
                foreach (IView view in views)
                {
                    ViewsComboBox.Items.Add(view);
                }
                ViewsComboBox.SelectedIndex = 0;
            }));

        }

        private void pagingControl1_NextButtonClick(int currentPageIndex, string listItemCollectionPositionNext)
        {
            if (After_PageChange != null)
                After_PageChange(currentPageIndex, listItemCollectionPositionNext);
        }

        private void pagingControl1_PreviousButtonClick(int currentPageIndex, string listItemCollectionPositionNext)
        {
            if (After_PageChange != null)
                After_PageChange(currentPageIndex, listItemCollectionPositionNext);
        }
    }
}
